package com.yonyougov.devops.cruxcisupport.k8s.rest.controller;

import com.yonyougov.devops.cruxcisupport.k8s.rest.service.K8sPodService;
import com.yonyougov.devops.cruxcisupport.k8s.resutl.ResultInfo;
import io.swagger.annotations.Api;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "pod资源Api")
@RestController
@RequestMapping(value = "/api/v2/kubernetes")
public class k8sPodController {
    @Autowired
    private K8sPodService podService;

    @GetMapping(value = "pod/del")
    @SneakyThrows
    public ResultInfo deletePod(@RequestParam String envName, @RequestParam String appName){
        if(StringUtils.isBlank(envName)){
            return ResultInfo.builder().status(false).detail("环境名称不能为空").build();
        }
        if(StringUtils.isBlank(appName)){
            return ResultInfo.builder().status(false).detail("应用名称不能为空").build();
        }
        boolean flag = podService.deletePod(envName,appName);
        return ResultInfo.builder().status(flag).build();
    }
}
